package org.dromara.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.bean.domain.bo.HisOpinionBo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bean.domain.vo.HisOpinionVo;
import org.dromara.system.service.IHisOpinionService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 意见反馈
 *
 * @author Lion Li
 * @date 2025-01-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/opinion")
public class HisOpinionController extends BaseController {

    private final IHisOpinionService hisOpinionService;


    /**
     * 查询意见反馈列表
     */
    @SaCheckPermission("system:opinion:list")
    @GetMapping("/list")
    public TableDataInfo<HisOpinionVo> list(HisOpinionBo bo, PageQuery pageQuery) {
        return hisOpinionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出意见反馈列表
     */
    @SaCheckPermission("system:opinion:export")
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HisOpinionBo bo, HttpServletResponse response) {
        List<HisOpinionVo> list = hisOpinionService.queryList(bo);
        ExcelUtil.exportExcel(list, "意见反馈", HisOpinionVo.class, response);
    }

    /**
     * 获取意见反馈详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:opinion:query")
    @GetMapping("/{id}")
    public R<HisOpinionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(hisOpinionService.queryById(id));
    }



    /**
     * 修改意见反馈
     */
    @SaCheckPermission("system:opinion:edit")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HisOpinionBo bo) {
        return toAjax(hisOpinionService.updateByBo(bo));
    }

    /**
     * 删除意见反馈
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:opinion:remove")
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hisOpinionService.deleteWithValidByIds(List.of(ids), true));
    }
}
